const mysql = require('mysql2');

const pool = mysql.createPool({
  host: '122.51.52.169',
  port: 3306,
  user: 'ataola',
  password: '123456',
  database: 'test',
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
});

function cmd(options, values) {
  return new Promise((resolve, reject) => {
    pool.getConnection(function (err, connection) {
      if (err) {
        reject(err);
      } else {
        connection.query(options, values, (err, results, fields) => {
          if (err) {
            reject(err);
          } else {
            resolve({ err, results, fields });
          }
          connection.release();
        });
      }
    });
  });
}

module.exports = {
  cmd,
};
